package com.manage.function.service.impl;

import java.util.List;

import com.manage.common.core.domain.entity.SysUser;
import com.manage.common.utils.SecurityUtils;
import com.manage.function.domain.Review;
import com.manage.system.domain.SysUserRole;
import com.manage.system.mapper.SysUserMapper;
import com.manage.system.mapper.SysUserRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.manage.function.mapper.FunctionSocialSecurityMapper;
import com.manage.function.domain.FunctionSocialSecurity;
import com.manage.function.service.IFunctionSocialSecurityService;

import javax.annotation.Resource;

/**
 * 社保记录Service业务层处理
 *
 * @author jinghj
 * @date 2025-03-13
 */
@Service
public class FunctionSocialSecurityServiceImpl implements IFunctionSocialSecurityService
{
    @Autowired
    private FunctionSocialSecurityMapper functionSocialSecurityMapper;
    @Resource
    private SysUserMapper sysUserMapper;

    @Resource
    private SysUserRoleMapper sysUserRoleMapper;

    /**
     * 查询社保记录
     *
     * @param id 社保记录主键
     * @return 社保记录
     */
    @Override
    public FunctionSocialSecurity selectFunctionSocialSecurityById(Long id)
    {
        return functionSocialSecurityMapper.selectFunctionSocialSecurityById(id);
    }

    /**
     * 查询社保记录列表
     *
     * @param functionSocialSecurity 社保记录
     * @return 社保记录
     */
    @Override
    public List<FunctionSocialSecurity> selectFunctionSocialSecurityList(FunctionSocialSecurity functionSocialSecurity)
    {
        List<FunctionSocialSecurity> functionSocialSecurities=null;
        String username = SecurityUtils.getUsername();
        SysUser sysUser = sysUserMapper.selectUserByUserName(username);
        Long userId = sysUser.getUserId();
        SysUserRole sysUserRole = sysUserRoleMapper.selectSysUserRoleByUserId(userId);
        if (sysUserRole.getRoleId()==1){
            functionSocialSecurities=functionSocialSecurityMapper.selectFunctionSocialSecurityList(functionSocialSecurity);
        }else {
            functionSocialSecurity.setUsername(username);
            functionSocialSecurities=functionSocialSecurityMapper.selectFunctionSocialSecurityList(functionSocialSecurity);
        }
       return functionSocialSecurities;
    }

    /**
     * 新增社保记录
     *
     * @param functionSocialSecurity 社保记录
     * @return 结果
     */
    @Override
    public int insertFunctionSocialSecurity(FunctionSocialSecurity functionSocialSecurity)
    {
        return functionSocialSecurityMapper.insertFunctionSocialSecurity(functionSocialSecurity);
    }

    /**
     * 修改社保记录
     *
     * @param functionSocialSecurity 社保记录
     * @return 结果
     */
    @Override
    public int updateFunctionSocialSecurity(FunctionSocialSecurity functionSocialSecurity)
    {
        return functionSocialSecurityMapper.updateFunctionSocialSecurity(functionSocialSecurity);
    }

    /**
     * 批量删除社保记录
     *
     * @param ids 需要删除的社保记录主键
     * @return 结果
     */
    @Override
    public int deleteFunctionSocialSecurityByIds(Long[] ids)
    {
        return functionSocialSecurityMapper.deleteFunctionSocialSecurityByIds(ids);
    }

    /**
     * 删除社保记录信息
     *
     * @param id 社保记录主键
     * @return 结果
     */
    @Override
    public int deleteFunctionSocialSecurityById(Long id)
    {
        return functionSocialSecurityMapper.deleteFunctionSocialSecurityById(id);
    }
}
